package com.szmirren.entity.ams;

import com.szmirren.common.StringUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lin
 * @date 2018/3/17
 */
public class TabSplitGenItem extends GenItem {
    public static final char CHAR_SEP = '|';

    private String realTable;
    private List<String> splitCols;
    private Map<String, Boolean> colExistsMap = new HashMap<>();

    public TabSplitGenItem(String tableName, String connName, String centerName, String modelName, String boName) {
        super(tableName, connName, centerName, modelName, boName);


        if (tableName.indexOf(CHAR_SEP) > 0) {
            String[] arr = tableName.split("\\|");
            if (arr.length > 1) {
                this.realTable = arr[1];
                String tabName = arr[0];
                int idx = tabName.indexOf("T[");
                setTableName(tabName.substring(idx + 2, tabName.indexOf(']', idx)));
                setSplitCols(StringUtil.getMatchList(tabName, "C[", "]"));
            }

        } else {
            System.out.println("tableName = " + tableName);

        }
    }

    public void setSplitCols(List<String> splitCols) {
        this.splitCols = splitCols;
        for (String col : splitCols) {
            colExistsMap.put(col, false);
        }
    }

}
